import java.lang.reflect.*;
/**
 * Created by codeczx on 2018/3/2.
 */
public class ProxyTest {
    interface IHello{
        void sayHello();
    }

    static class IHelloImpl implements IHello{

        @Override
        public void sayHello() {
            System.out.println("hello world!");
        }
    }

    static class MyInvoketionHandler implements InvocationHandler{
        private Object target;

        public MyInvoketionHandler(Object target){
            this.target = target;
        }
        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return method.invoke(target,args);
        }
    }

    public static void main(String[] args) {
        InvocationHandler invocationHandler = new MyInvoketionHandler(new IHelloImpl());
        IHello iHello = (IHello) Proxy.newProxyInstance(IHello.class.getClassLoader(),new Class[]{IHello.class},invocationHandler);
        iHello.sayHello();
    }
}
